package dk.android.houseenabler.models;

import java.io.Serializable;
import java.util.ArrayList;

public class HouseCollection implements Serializable {
	

	private static final long serialVersionUID = 2432416221194673830L;
	private ArrayList<House> houses = new ArrayList<House>();
	
	public void addHouse(House house)
	{
		houses.add(house);
	}
	
	public ArrayList<House> getHouses()
	{
		return houses;
	}
	public int getLastIndex()
	{
		if (!houses.isEmpty()) {
			return houses.size()-1;
			}
		else
			return -1;
	}
	

	public void removeHouse(House house)
	{
		houses.remove(house);
	}
	
	public void removeHouse(int i)
	{
		houses.remove(i);
	}

	public House getHouse(String name)
	{
		House house = null;
		try{
		for(int i = 0; i<houses.size();i++)
		{
			if(houses.get(i).getTitle().equals(name))
				house = houses.get(i);
		}
		}
		catch(Exception e)
		{
			
		}
			return house;
	}
	public House getHouse(int index)
	{
		House house = null;
		for(int i = 0; i<houses.size();i++)
			{
				if(houses.get(i).getId() == index)
					house = houses.get(i);
			}
				return house;
	}

}
